<template>
	<view class="shopMember">
		<view class="dheader">
			<view class="shop">
				<image :src="shop_info.category_image" mode="aspectFill" class="Boutique"></image>
				<view class="title">
					{{shop_info.shop_name}}
				</view>
				<view class="right" @click="toggle">
					<view class="size">
						切换
					</view>
					<image :src="$IMG_URL('/static/home/indicate.png')" mode="aspectFill" class="icon"></image>
				</view>
			</view>
			<view class="search">
				<u-search placeholder="搜索学员昵称" :show-action="false" shape="square" v-model="query.search"
					@change="$u.debounce(getSearch,500)"></u-search>
			</view>
		</view>
		<view class="tab">
			<view v-for="(item,index) in tabList" :key="index" class="tabIndex" @click="changeIndex(index)">
				<view :class="activeIndex == index ?'tabsize1':'tabsize2'">
					{{item}}
				</view>
				<view class="active">
					<view class="empty" v-if="activeIndex == index">
					</view>
				</view>
			</view>
		</view>
		<scroll-view scroll-y="true" class="scroll-Y" @scrolltolower="scrolltolower">
			<view class="comlumn_box" v-if="list.length">
				<view v-for="(item,index) in list" :key="index" class="Item" @click.stop="routeDeatil(item, index)">
					<view class="img">
						<image :src="item.avatar" mode="aspectFill" class="avater"
							@click.stop="$PREVIEW_IMAGE(item.avatar)"></image>
						<image
							:src="!item.gender ?$IMG_URL('/static/mannager/girl.png'):$IMG_URL('/static/mannager/boy.png')"
							mode="" class="sex"></image>
					</view>
					<view class="right">
						<view class="title">
							{{item.nickname}}
						</view>
						<view class="bottom">
							<text class="size1" v-if="item.is_course">{{item.course_str}}</text>
							<text class="size2" v-else>{{item.course_str}}</text>
						</view>
					</view>
					<u-icon name="arrow-right" color="#999999" size="14"></u-icon>
				</view>
				<u-loadmore :status="status" />
			</view>
			<empty v-else :content="!activeIndex?'会员':activeIndex == 1?'进行中课程会员':'无课程会员'"></empty>
		</scroll-view>
		<FieldPopupVue :popupShow="popupShow" :FieldList="Field" @sure="sure" @changeActiveIndex="changeActiveIndex"
			:activeIndex="FieldIndex"></FieldPopupVue>
	</view>
</template>

<script>
	import FieldPopupVue from '../../pages/user/components/Field-popup.vue'
	import {
		atShop,
		memberDetailsList
	} from '@/api/manager.js'
	import empty from './components/empty.vue'
	export default {
		components: {
			FieldPopupVue,
			empty
		},
		data() {
			return {
				// 切换门店
				popupShow: false,
				shop_info: {},
				FieldIndex: -1,
				shopName: '',
				tabList: [
					'全部(0)',
					'课程进行中(0)',
					'暂无课程(0)'
				],
				activeIndex: 0,
				query: {
					shop_id: '',
					search: '',
					form: 'all',
					page: 1
				},
				list: [],
				status: 'loadmore', //当前状态
			}
		},
		onLoad() {
			this.getatShop()
		},
		methods: {
			scrolltolower() {
				this.query.page++
				this.getcoachList()
			},
			getSearch() {
				this.list = []
				this.query.page = 1
				this.getcoachList()

			},
			getcoachList() {
				memberDetailsList(this.query).then(({
					data: res
				}) => {
					console.log('res', res);
					if (res.code == 1) {
						this.tabList[0] = '全部(' + res.data.all_num + ')'
						this.tabList[1] = '课程进行中(' + res.data.course_num + ')'
						this.tabList[2] = '暂无课程(' + res.data.uncourse_num + ')'
						const list = []
						this.status = 'loading'
						if (this.query.page > res.data.all_page) {
							console.log('nomore');
							this.status = 'nomore'
							return false
						} else {
							console.log('more');
							this.status = 'more'
							this.list = this.list.concat(res.data.list)
						}

						console.log('list', this.list);
					}
				})
			},
			getatShop(e) {
				atShop(e).then(({
					data: res
				}) => {
					console.log('res', res);
					if (res.code == 1) {
						this.shop_info = res.data
						this.query.shop_id = res.data.shop_id
						this.list = []
						this.query.page = 1
						this.getcoachList()
					}
				})
			},
			toggle() {
				console.log(11);
				this.popupShow = true
			},
			changeIndex(index) {

				if (this.activeIndex != index) {
					if (!index) {
						this.query.form = 'all'
					} else if (index == 1) {
						this.query.form = 'course'
					} else if (index == 2) {
						this.query.form = 'uncourse'
					}
					this.activeIndex = index
					this.list = []
					this.query.page = 1
					this.getcoachList()
				}
			},
			changeActiveIndex(item, index) {
				this.FieldIndex = index
				this.getatShop({
					shop_id: item.shop_id
				})
			},
			sure() {
				this.popupShow = false
			},
			routeDeatil(item, index) {
				uni.navigateTo({
					url: 'course?user_id=' + item.user_id
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background: #e9e9e9;
	}

	.shopMember {
		display: flex;
		flex-direction: column;
		align-items: center;

		.dheader {
			width: 750rpx;
			height: 184rpx;
			background: #ffffff;
			padding: 26rpx 34rpx 0;

			.shop {
				width: 100%;
				display: flex;
				flex-direction: row;
				align-items: center;
				margin-bottom: 22rpx;

				.Boutique {
					width: 114rpx;
					height: 36rpx;
					margin-right: 12rpx;
				}

				.title {
					flex: 1;
					font-size: 28rpx;
					font-family: PingFang SC, PingFang SC-Bold;
					font-weight: 700;
					text-align: left;
					color: #333333;
				}

				.right {
					display: flex;
					flex-direction: row;
					align-items: center;

					.size {
						font-size: 28rpx;
						font-family: PingFang SC, PingFang SC-Regular;
						font-weight: 400;
						color: #666666;
						margin-right: 8rpx;
					}

					.icon {
						width: 10rpx;
						height: 16rpx;
					}
				}
			}

			.search {
				width: 100%;
			}


		}

		.tab {
			width: 750rpx;
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-around;
			background: #ffffff;

			.tabIndex {
				display: flex;
				flex-direction: column;
				align-items: center;

				.tabsize1 {
					height: 44rpx;
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC-Heavy;
					font-weight: 800;
					text-align: center;
					color: #73F0EA;
					letter-spacing: 0.7rpx;

				}

				.tabsize2 {
					height: 44rpx;
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC-Regular;
					font-weight: 400;
					text-align: center;
					color: #666666;
					letter-spacing: 0.7rpx;

				}

				.active {
					margin-top: 12rpx;
					width: 44rpx;
					height: 8rpx;

					.empty {
						width: 100%;
						height: 100%;
						background: #73F0EA;
						border: 2rpx solid rgba(0, 0, 0, 0.00);
						border-radius: 2rpx;
					}
				}
			}
		}

	}

	.scroll-Y {
		width: 100%;
		height: 80vh;

		.comlumn_box {
			display: flex;
			flex-direction: column;
			align-items: center;
			padding-top: 24rpx;

			.Item {
				width: 702rpx;
				height: 128rpx;
				background: #ffffff;
				border-radius: 16rpx;
				padding: 0 24rpx;
				display: flex;
				flex-direction: row;
				align-items: center;
				margin-bottom: 20rpx;

				.img {
					width: 80rpx;
					height: 80rpx;
					background: #f6f6f6;
					border-radius: 50%;
					position: relative;
					margin-right: 20rpx;

					.avater {
						width: 100%;
						height: 100%;
						border-radius: 50%;
					}

					.sex {
						position: absolute;
						right: 0;
						bottom: 0;
						width: 26rpx;
						height: 26rpx;
					}
				}
			}

			.right {
				display: flex;
				flex-direction: column;
				flex: 1;

				.title {
					font-size: 32rpx;
					font-family: PingFang SC, PingFang SC-Bold;
					font-weight: 700;
					text-align: left;
					color: #333333;
					margin-bottom: 2rpx;
				}

				.bottom {
					.size1 {
						font-size: 24rpx;
						font-family: PingFang SC, PingFang SC-Regular;
						font-weight: 400;
						text-align: left;
						color: #000000;
					}

					.size2 {
						font-size: 24rpx;
						font-family: PingFang SC, PingFang SC-Regular;
						font-weight: 400;
						text-align: left;
						color: #b6b6b6;
					}
				}
			}
		}
	}
</style>